package com.mentaleye.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.OaClassBean;
import com.mentaleye.dal.dao.OaClassDao;
import com.mentaleye.dal.model.OaClass;
import com.mentaleye.dal.model.OaClassExample;
import com.mentaleye.dal.model.OaClassExample.Criteria;
import com.mentaleye.service.OaClassService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;



@Service
public class OaClassServiceImpl implements OaClassService{
	
	@Autowired private OaClassDao oaclassDao;

	@Override
	public boolean oaClassAdd(OaClassBean oaclassBean) {
		oaclassBean.setOaclassCreateTime(new Date());
		OaClass oaclass = (OaClass) ObjectUtil.transfer(oaclassBean, OaClass.class);
		return oaclassDao.addOaClass(oaclass);
	}

	@Override
	public boolean oaClassUpdate(OaClassBean oaclassBean) {
		oaclassBean.setOaclassUpdateTime(new Date());
		OaClass oaclass = (OaClass) ObjectUtil.transfer(oaclassBean, OaClass.class);
		return oaclassDao.updateOaClass(oaclass);
	}
	
	@Override
	public boolean oaClassUpdateList(List<Integer> ids,OaClassBean oaclassBean){
		if(ids.size()>0 && oaclassBean != null){
			OaClass oaclass = (OaClass) ObjectUtil.transfer(oaclassBean, OaClass.class);
			return oaclassDao.updateOaClassByList(ids, oaclass);
		}
		return false;
	}

	@Override
	public boolean oaClassDrop(List<Integer> ids) {
		if(ids.size()>0){
			return oaclassDao.deleteOaClass(ids);
		}
		return false;
	}
	
	@Override
	public boolean deleteOaClassNotIn(List<Integer> ids){
		if(ids.size()>0){
			return oaclassDao.deleteOaClassNotIn(ids);
		}
		return false;
	}
	

	@Override
	public void queryOaclassList(CommonPage commonPage) {
		List<OaClass> data = oaclassDao.selectOaclassList(commonPage.pageToMap());
		commonPage.setPageData(data);
	}
	
	public OaClassBean queryOaclassById(Integer oaclassId){
		return (OaClassBean) ObjectUtil.transfer(oaclassDao.selectOaclassById(oaclassId), OaClassBean.class);
	}

	@Override
	public OaClassBean queryOaclassData(int oaclassId, String oaclassName) {
		OaClass oaclass = new OaClass();
		if(oaclassId != 0){
			oaclass.setOaclassId(oaclassId);
		}
		if(oaclassName != null){
			oaclass.setOaclassName(oaclassName);
		}
		return (OaClassBean) ObjectUtil.transfer(oaclassDao.selectOaclassData(oaclass), OaClassBean.class);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<OaClassBean> queryOaclass(OaClassExample example) {
		return ObjectUtil.transferList(oaclassDao.select(example), OaClassBean.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<OaClassBean> queryAllOaClass() {
		return ObjectUtil.transferList(oaclassDao.selectAllOaClass(), OaClassBean.class);
	}
	
	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.oaclassDao.getListByMap(map);
	}

	@Override
	public int getCountByName(String className) {
		OaClassExample example=new OaClassExample();
		Criteria criteria = example.createCriteria();
		criteria.andOaclassNameEqualTo(className);
		return this.oaclassDao.getCountByExample(example);
	}
}
